package cn.wolfcode.springcloud.controller;

import cn.wolfcode.springcloud.domain.Product;
import cn.wolfcode.springcloud.service.IProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@RestController
//@RequestMapping("products")
public class ProductController {
    @Autowired
    private IProductService productService;
//获取配置文件中的端口
  @Value("${server.port}")
  private String port;

    @GetMapping("/get/{id}")
    private Object get(@PathVariable Long id){
        Product product=productService.get(id);
        //让order-server服务调用product集群接口时知道调用哪一个接口
        //是8080还是8090
        //product.setName(product.getName()+"_"+port);
        //保证放在map中的数据没有改动
        Product pp = new Product();
        BeanUtils.copyProperties(product,pp);
        pp.setName(product.getName() + "_" + port);
        return pp;

    }
}